
import React from 'react';
import _ from 'lodash';
import { ColumnFieldBase } from '../../../typings/ColumnFieldBase';
import { bizUtil } from '../../../utils';

type LinkColumnFieldProps = ColumnFieldBase & {
  linkKey: string;  // 跳转链接的key值
  target: string; // 规定在何处打开链接文档
};

const LinkColumnField: React.FC<LinkColumnFieldProps> = (props) => {
  const { value, pipes, item, linkKey, target } = props;
  const finalValue = bizUtil.executePipes(value, pipes);
  return (
    <a style={{ wordBreak: 'break-all' }} href={_.get(item, linkKey)} target={target}>
      {finalValue}
    </a>
  )
}

export {
  LinkColumnFieldProps,
  LinkColumnField
}
